#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MX=1000100;
int n,m,L,V,a[MX],d[MX],v[MX],p[MX],u[MX],box[MX],cnt;
int fast_big(int x,int y){
    int t=0;
    while(x<V){
        x+=y;
        t++;
    }
    return t;
}
int fast_small(int x,int y){
    int t=0;
    if(x<V)return -1;
    while(x>V){
        x+=y;
        t++;
    }
    return t;
}
signed main(){
    int T;
    cin >> T;
    while(T--){
        cin >> n >> m >> L >> V;
        for(int i=1;i<=n;i++)cin >> d[i] >> v[i] >> a[i];
        for(int i=1;i<=m;i++)cin >> p[i];
        for(int i=1;i<=n;i++){
            if(a[i]>0){
                int t=fast_big(v[i],a[i]);
                int s=(v[i]*t)+(a[i]*t*t/2);
                if(d[i]+s<=p[m]){
                    int e=m;
                    while(d[i]+s<=p[e]){
                        e--;
                    }
                    u[i]=e+1;
                    cnt++;
                }
            }
            else if(a[i]==0){
                if(v[i]>V){
                    int e;
                    while(e<m){
                        e++;
                        if(p[e]<d[i])continue;
                    }
                    u[i]=e;
                    cnt++;
                }
            }
            else {
                int t=fast_small(v[i],a[i]);
                int s=(v[i]*t)+(a[i]*t*t/2);
                int e=0;
                while(e<=m){
                    e++;
                    if(p[e]>s+d[i]||d[i]>p[e])continue;
                }
                u[i]=e;
                cnt++;
            }
        }
        cout << cnt << " ";
        cnt=0;
        for(int i=1;i<=n;i++)box[u[i]]++;
        for(int i=1;i<=m;i++){
            if(box[i]==0)cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}
